package site.isscloud.project.domain;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import site.isscloud.common.annotation.Excel;
import site.isscloud.common.core.domain.TreeEntity;

/**
 * 空间管理对象 pj_location
 *
 * @author junhuang
 * @date 2025-10-14
 */
public class PjLocation extends TreeEntity
{
    private static final long serialVersionUID = 1L;

    // 在PjLocation类中添加parentCode字段
    /** 父空间编码（用于导入） */
    @Excel(name = "父空间编码")
    private String parentCode;

    /** 空间id */
    private Long lcId;

    /** 空间父亲id */
//    @Excel(name = "空间父亲id")
    private Long lcPid;

    /** 空间编码 */
    @Excel(name = "空间编码")
    private String lcCode;

    /** 空间名称 */
    @Excel(name = "空间名称")
    private String lcName;

    /** 空间描述 */
    @Excel(name = "空间描述")
    private String lcDesc;

    /** 空间状态 */
    @Excel(name = "空间状态")
    private String status;

    /** 设备编号 - 来自 pj_location_marker 表 */
    @Excel(name = "设备编号")
    private String deviceNo;

    /** 通道号 - 来自 pj_location_marker 表 */
    @Excel(name = "通道号")
    private Integer channelNo;

    /** 起始米标 - 来自 pj_location_marker 表 */
    @Excel(name = "起始米标")
    private Integer startMeter;

    /** 结束米标 - 来自 pj_location_marker 表 */
    @Excel(name = "结束米标")
    private Integer endMeter;

    /** 位置标记ID - 用于关联操作 */
    private Long markerId;

    public void setLcId(Long lcId)
    {
        this.lcId = lcId;
    }

    public Long getLcId()
    {
        return lcId;
    }

    public void setLcPid(Long lcPid)
    {
        this.lcPid = lcPid;
    }

    public Long getLcPid()
    {
        return lcPid;
    }

    public void setLcCode(String lcCode)
    {
        this.lcCode = lcCode;
    }

    public String getLcCode()
    {
        return lcCode;
    }

    public void setLcName(String lcName)
    {
        this.lcName = lcName;
    }

    public String getLcName()
    {
        return lcName;
    }

    public void setLcDesc(String lcDesc)
    {
        this.lcDesc = lcDesc;
    }

    public String getLcDesc()
    {
        return lcDesc;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getStatus()
    {
        return status;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    // 新增字段的getter和setter
    public String getDeviceNo() {
        return deviceNo;
    }

    public void setDeviceNo(String deviceNo) {
        this.deviceNo = deviceNo;
    }

    public Integer getChannelNo() {
        return channelNo;
    }

    public void setChannelNo(Integer channelNo) {
        this.channelNo = channelNo;
    }

    public Integer getStartMeter() {
        return startMeter;
    }

    public void setStartMeter(Integer startMeter) {
        this.startMeter = startMeter;
    }

    public Integer getEndMeter() {
        return endMeter;
    }

    public void setEndMeter(Integer endMeter) {
        this.endMeter = endMeter;
    }

    public Long getMarkerId() {
        return markerId;
    }

    public void setMarkerId(Long markerId) {
        this.markerId = markerId;
    }

    /**
     * 获取空间层级
     * 根据lc_code中的'-'分隔符数量确定层级
     * 没有'-'为1级，有一个为2级，以此类推
     * @return 空间层级
     */
    public int getLevel() {
        if (lcCode == null || lcCode.isEmpty()) {
            return 0;
        }

        int separatorCount = 0;
        for (char c : lcCode.toCharArray()) {
            if (c == '-') {
                separatorCount++;
            }
        }

        return separatorCount + 1;
    }

    /**
     * 获取层级名称
     * 根据lc_name中的'-'分隔符，取最后分隔出的名字
     * @return 层级名称
     */
    public String getLevelName() {
        if (lcName == null || lcName.isEmpty()) {
            return "";
        }

        // 按'-'分隔名称
        String[] parts = lcName.split("-");
        if (parts.length == 0) {
            return lcName;
        }

        // 直接返回最后一部分
        return parts[parts.length - 1].trim();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
                .append("parentCode", getParentCode())
                .append("lcId", getLcId())
                .append("lcPid", getLcPid())
                .append("lcCode", getLcCode())
                .append("lcName", getLcName())
                .append("lcDesc", getLcDesc())
                .append("status", getStatus())
                .append("deviceNo", getDeviceNo())
                .append("channelNo", getChannelNo())
                .append("startMeter", getStartMeter())
                .append("endMeter", getEndMeter())
                .append("markerId", getMarkerId())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .toString();
    }
}